package henu.graduation_design.tool;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class AnalyseCartJson {

	private JSONObject jsonObject;
	static List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();

	public AnalyseCartJson(JSONObject jsonObject) {
		this.jsonObject = jsonObject;
	}

	public List<HashMap<String, Object>> getList() throws JSONException {
		list.clear();
		JSONArray jsonArray = jsonObject.getJSONArray("getCartResult");
		for (int i = 0; i < jsonArray.length(); i++) {
			HashMap<String, Object> temp = new HashMap<String, Object>();
			JSONObject jsonObject = jsonArray.getJSONObject(i);
			temp.put("imageUri", jsonObject.getString("imageUri"));
			temp.put("name", jsonObject.getString("name"));
			temp.put("id", jsonObject.getInt("id"));
			temp.put("intro", jsonObject.getString("intro"));
			temp.put("price", jsonObject.getDouble("price"));
			temp.put("OriginalPrice", jsonObject.getDouble("originalPrice"));
			list.add(temp);
		}
		return list;
	}

}
